<template>
    <div>
        <el-form :model="queryParams" ref="queryRef" :inline="true" v-show="showSearch" label-width="68px">
            <el-form-item label="标题1" prop="category">
                <el-input
                    v-model="queryParams.category"
                    placeholder="请输入标题1"
                    clearable
                    @keyup.enter="handleQuery"
                />
            </el-form-item>
            <el-form-item>
                <el-button type="primary" icon="Search" @click="handleQuery">搜索</el-button>
                <el-button icon="Refresh" @click="resetQuery">重置</el-button>
            </el-form-item>
        </el-form>
        <el-row :gutter="10" class="mb8">
            <el-col :span="1.5">
                <el-button
                    type="primary"
                    plain
                    icon="Plus"
                    @click="handleAdd"
                >新增
                </el-button>
            </el-col>
            <right-toolbar v-model:showSearch="showSearch" @queryTable="getList"></right-toolbar>
        </el-row>
        <el-table v-loading="loading" :data="dataList">
            <el-table-column label="标题1" align="center" prop="category" />
            <el-table-column label="标题2" align="center" prop="price" />
            <el-table-column label="标题3" align="center" prop="stocked" />
            <el-table-column label="标题4" align="center" prop="name"/>
            <el-table-column label="操作" align="center" class-name="small-padding fixed-width" width="250">
                <template #default="scope">
                    <el-button link type="primary" icon="Edit"
                    >详情
                    </el-button>
                </template>
            </el-table-column>
        </el-table>
        <pagination
            v-show="total>0"
            :total="total"
            v-model:page="queryParams.pageNum"
            v-model:limit="queryParams.pageSize"
            @pagination="getList"
        />
    </div>
</template>

<script setup>
import axios from "axios";
import {onMounted, reactive, ref, toRefs} from "vue";
const total = ref(0);
const loading = ref(true);
const dataList = ref([]);
const showSearch = ref(true);
const data = reactive({
    queryParams: {
        pageNum: 1,
        pageSize: 10,
        category:"",
    },
});
const {queryParams} = toRefs(data);
const getList = ()=> {
    loading.value = true
    axios.get('http://localhost:3008/productList').then(res=>{
        console.log("get",res)
        dataList.value = res.data
        total.value = res.data.length;
        loading.value = false;
    })
}
const handleAdd = ()=> {
    axios.post('http://localhost:3008/productList',{
        category: "abcd Goods",
        price: "$77.99",
        stocked: 1,
        name: "abcdefg",
    }).then(res=>{
        console.log("post",res)
    })
}
onMounted(()=>{
    getList()
})
</script>

<style lang="scss" scoped>

</style>
